﻿using System;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace Needle.Bus.Transport.Impl.WCF
{

    // TODO: read this stuff from a configuration file.
    public static class WCFSettings
    {

        private static SecurityMode _SecurityMode = SecurityMode.Message;
        public static SecurityMode SecurityMode
        {
            get { return _SecurityMode; }
        }

        private static int _Port = 2345;
        public static int Port
        {
            get { return _Port; }
        }
        
       public static Binding Binding
        {
            get { return new NetTcpBinding(WCFSettings.SecurityMode); }
        }

        public static EndpointAddress Address<T>(string topic)
        {
            return new EndpointAddress(WCFSettings.Url<T>(topic));  
        }

        public static string Url<T>(string topic)
        {
            return String.Format("{0}://{1}:{2}/{3}/{4}", Binding.Scheme, Environment.MachineName, WCFSettings.Port, topic, typeof(T).GUID.ToString("N").ToUpperInvariant());
        }

    }
}
